package com.csu.express.controller.app;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.csu.common.exception.WebException;
import com.csu.common.vo.ResultVo;
import com.csu.express.service.CommonService;
import com.csu.express.vo.HeartbeatMsgVo;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;

/**
 * @项目名称：express
 * @类名称：CommonController
 * @类描述：
 * @创建人：Tangc
 * @创建时间：2017年9月21日 下午3:38:54
 * @company:
 */
@Controller
@RequestMapping("/common")
@Api(value = "common", description = "通用服务接口")
public class CommonController
{

    @Autowired
    private CommonService commonService;

    @ResponseBody
    @ApiOperation(value = "发送注册短信验证码", notes = "验证码通过短信发送，成功返回success")
    @RequestMapping(value = "sendSignCode/{cellphone}", method = RequestMethod.GET, produces = { "application/json; charset=utf-8" })
    public ResultVo<Boolean> sendSignCode(HttpServletRequest request,
            @ApiParam(value = "电话号码") @PathVariable(value = "cellphone") String cellphone) throws WebException
    {
        ResultVo<Boolean> result = new ResultVo<Boolean>();
        Boolean send = commonService.sendSignCode(cellphone);
        result.setData(send);
        return result;
    }

    @ResponseBody
    @ApiOperation(value = "心跳接口", notes = "客户端轮询心跳接口")
    @RequestMapping(value = "heartbeat/customerId/{customerId}", method = RequestMethod.GET, produces = { "application/json; charset=utf-8" })
    public ResultVo<List<HeartbeatMsgVo>> heartbeatCsutomer(HttpServletRequest request,
            @ApiParam(value = "用户id") @PathVariable(value = "customerId") Integer customerId) throws WebException
    {
        ResultVo<List<HeartbeatMsgVo>> result = new ResultVo<List<HeartbeatMsgVo>>();
        List<HeartbeatMsgVo> heartbeatMsgs = commonService.heartbeat(customerId, 1);
        result.setData(heartbeatMsgs);
        return result;
    }

    @ResponseBody
    @ApiOperation(value = "心跳接口", notes = "司机端端轮询心跳接口")
    @RequestMapping(value = "heartbeat/driver", method = RequestMethod.POST, produces = { "application/json; charset=utf-8" })
    public ResultVo<List<HeartbeatMsgVo>> heartbeatDriver(HttpServletRequest request,
            @ApiParam(value = "用户id") @PathVariable(value = "driverId") Integer driverId) throws WebException
    {
        ResultVo<List<HeartbeatMsgVo>> result = new ResultVo<List<HeartbeatMsgVo>>();
        List<HeartbeatMsgVo> heartbeatMsgs = commonService.heartbeat(driverId, 2);
        result.setData(heartbeatMsgs);
        return result;
    }

}
